export default function createStore(reducer, enhancer) {
  if (enhancer) {
    return enhancer(createStore)(reducer);
  }
  let curState;
  let curListener = [];
  function getState() {
    return curState;
  }
  function dispatch(action) {
    curState = reducer(curState, action);
    curListener.forEach(listener => listener());
  }
  function subscribe(listener) {
    curListener.push(listener);
    return () => {
      // 自己实现过滤
      curListener = [];
    };
  }

  dispatch({ type: "REDUX/KKKB" });

  return {
    getState,
    subscribe,
    dispatch
  }
}